VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "ESC.17/01/10/12 -Cupom Fiscal"
   ClientHeight    =   2130
   ClientLeft      =   3645
   ClientTop       =   1875
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   2130
   ScaleWidth      =   4680
   Begin VB.CommandButton Command1 
      Caption         =   "Cupom Fiscal"
      Height          =   495
      Left            =   1680
      TabIndex        =   0
      Top             =   480
      Width           =   1335
   End
   Begin VB.Label Label2 
      Caption         =   "Label2"
      Height          =   855
      Left            =   120
      TabIndex        =   1
      Top             =   1200
      Width           =   4335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function Abre Lib "SWECF.DLL" Alias "ECFOpen" (ByVal Numero As Long, ByVal Tempo As Long, ByVal Log As Long, ByVal Mostra As Long) As Long
Private Declare Function Fecha Lib "SWECF.DLL" Alias "ECFClose" () As Long
Private Declare Function Grava Lib "SWECF.DLL" Alias "ECFWrite" (ByVal Comando As String) As Long
Private Declare Function Retorna Lib "SWECF.DLL" Alias "ECFRead" (ByVal Status As String, ByVal Extensao As Long) As Long

Private Sub Command1_Click()

     Dim Status As String
     Dim texto As String
     Dim VLItem As String
     
     dll1 = Abre(1, 2, 1, 1)
' Abre cupom
     Status = Space(512)
     Comando = Chr(27) & ".17}"
     dll2 = Grava(Comando)
     dll3 = Retorna(Status, 512)
     Label2.Caption = "Status = " & Status
    
     VLItem = ""
'||||Vende item
For i = 1 To 5
          
     Status = Space(512)
     
     'comando stx
     texto = Chr(2) & "*02|1|12345678901234|1,00|UN|I1|produto teste|T" & Chr(3)
     CS = CalculoCS(texto)
     ' comando stx encapsulado pelo protocolo ESC, pois a dll não aceita se o comando não for ESC.
     Comando = Chr(27) & "." & texto & CS & "}"
     
     dll2 = Grava(Comando)
     dll3 = Retorna(Status, 512)
     Label2.Caption = "Status = " & Status
    
     
     Status = Space(512)
     Comando = Chr(27) & ".28}"

     
     dll2 = Grava(Comando)
     dll3 = Retorna(Status, 512)
     
     'Valida a venda liquida, se for igual ao do item anterior, é pq não imprimiu o item
     If VLItem = Mid(Status, 22, 12) Then
        MsgBox "erro item não impresso"
     Else
        VLItem = Mid(Status, 22, 12)
     End If
     
     Label2.Caption = "Status = " & Status
   Next
     
Status = Space(512)
     Comando = Chr(27) & ".1001000000000500}"
     dll1 = Abre(1, 2, 1, 1)
     dll2 = Grava(Comando)
     dll3 = Retorna(Status, 512)
     Label2.Caption = "Status = " & Status
    

     
Status = Space(512)
     Comando = Chr(27) & ".12NN0         OBRIGADO PELA PREFERENCIA      }"
     dll2 = Grava(Comando)
     dll3 = Retorna(Status, 512)
     Label2.Caption = "Status = " & Status

End Sub

Function CalculoCS(texto As String) As String
 Dim i As Integer
 Dim Cont As Integer
 Cont = 0
 
 For i = 1 To Len(texto)
 
 Cont = Cont + Asc(Mid(texto, i, 1))
 
 Next
 Cont = Cont Mod 256
 CalculoCS = Chr(Cont)
End Function



Private Sub Form_Unload(Cancel As Integer)
    dll4 = Fecha()
End Sub
